from django.db import models

# Create your models here.
class Admin(models.Model):
    username = models.CharField(verbose_name="用户名",max_length=32)
    password = models.CharField(verbose_name="密码",max_length=64)
    def __str__(self):
        return self.username

class Department(models.Model):
    title=models.CharField(verbose_name='标题',max_length=32)
    def __str__(self):
        return self.title

class UserInfo(models.Model):
    # 员工表
    name=models.CharField(verbose_name="姓名",max_length=16)
    password=models.CharField(verbose_name="密码",max_length=64)
    age=models.IntegerField(verbose_name="年龄")
    account=models.DecimalField(verbose_name="账户余额",max_digits=10,decimal_places=2,default=0)
    # create_time=models.DateTimeField(verbose_name="入职时间")
    create_time=models.DateField(verbose_name="入职时间")
    # 以下为外键写法：生成数据列时会再自动加一个后缀,实际名字为depart_id
    # to 和 to_field分别对应关联的表名和列名，这时这个外键列的数字是有约束条件的，只能是department中存在的ID
    # 当department中的部门被删除时，此表中的depart_id列可以有如下两个选择：级联删除或置空
    depart=models.ForeignKey(verbose_name="部门",to="Department",to_field="id",on_delete=models.CASCADE)
    # depart=models.ForeignKey(to="Department",null=True,blank=True,on_delete=models.SET_NULL)

    #性别列的写法：性别只有两种，一般不会再搞一个单独的表，会在django中单独定义一个元祖（和数据库无关），写法如下:
    gender_choices=(
        (1,"男"),
        (2,"女"),
    )
    gender =models.SmallIntegerField(verbose_name="性别",choices=gender_choices)

class PrettyNum(models.Model):
    mobile=models.CharField(verbose_name="手机号",max_length=11)
    price=models.IntegerField(verbose_name="价格",default=0)
    level_choices=(
        (1,"一級"),
        (2,"二級"),
        (3,"三級"),
        (4,"四級"),
    )
    level=models.SmallIntegerField(verbose_name="级别", choices=level_choices,default=1)
    status_choices=(
        (1,"已佔用"),
        (2,"未佔用")
    )
    status=models.SmallIntegerField(verbose_name="状态", choices=status_choices,default=2)

class Task(models.Model):
    level_choices = (
        (1,"紧急"),
        (2,"重要"),
        (3,"临时"),
    )
    level = models.SmallIntegerField(verbose_name="级别",choices=level_choices,default=1)
    title = models.CharField(verbose_name="标题",max_length=64)
    detail = models.TextField(verbose_name="详细信息")
    user = models.ForeignKey(verbose_name="负责人",to="Admin",on_delete=models.CASCADE)

class Order(models.Model):
    oid = models.CharField(verbose_name="订单号",max_length=64)
    title = models.CharField(verbose_name="名称",max_length=32)
    price =models.IntegerField(verbose_name="价格")
    status_choices =(
        (1,"待支付"),
        (2,"已支付"),
    )
    status = models.SmallIntegerField(verbose_name="状态",choices=status_choices,default=1)
    admin = models.ForeignKey(verbose_name="管理员",to="Admin",on_delete=models.CASCADE)
